import { getCurrentInstance } from 'vue';

// 主题类型定义
export type Theme = 'light' | 'dark';

// 初始化主题
export const initTheme = () => {
  const savedTheme = localStorage.getItem('app-theme') as Theme || 'light';
  if (savedTheme === 'dark') {
    document.documentElement.classList.add('dark');
  }
};

// 切换主题
export const toggleTheme = (): Theme => {
  const isDark = document.documentElement.classList.toggle('dark');
  const newTheme = isDark ? 'dark' : 'light';
  localStorage.setItem('app-theme', newTheme);
  return newTheme;
};